#include "spinlock.h"


void initlock(struct spinlock *lk, char *name){
  lk->name = name;
  lk->is_locked = 0;
  pthread_spin_init(&(lk->locked), PTHREAD_PROCESS_SHARED);
}

void acquire(struct spinlock * lk){
  pthread_spin_lock(&(lk->locked));
  lk->is_locked = 1;
}
void release(struct spinlock * lk){
  lk->is_locked = 0;
  pthread_spin_unlock(&(lk->locked));
}

int holding(struct spinlock * lk){
  return lk->is_locked;
}

void destroylock(struct spinlock * lk){
  pthread_spin_destroy(&(lk->locked));
  lk->is_locked = 0;
  lk->name = (char *)0x0;
}
